#if !defined(OSCILLOSCOPECTRLH)
#define OSCILLOSCOPECTRLH

#include <AfxTempl.h>

/////////////////////////////////////////////////////////////////////////////
// COscilloscopeCtrl	
// An Oscilloscope like control with support for multiple bands
// Author: Tanzim Husain [tanzim@mail.com]
// Based on Mousavi Mehdi[mehdi_mousavi@hotmail.com]'s CHistogramCtrl
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// COscilloscopeBand	
// An Oscilloscope band
/////////////////////////////////////////////////////////////////////////////
class COscilloscopeBand
{
public:
	COscilloscopeBand(); // Default constructor to keep CArray happy
	COscilloscopeBand(LPCTSTR lpszName, COLORREF crColor, int nWidth, UINT uLower, UINT uUpper, UINT uOffset);	
	~COscilloscopeBand();

public:
	void SetName(LPCTSTR lpszName) { m_strName = lpszName; }
	void SetRange(UINT uLower, UINT uUpper);
	void SetPen(int nWidth, COLORREF crColor);
	void SetPos(UINT uPos);
	void SetOffset(UINT uOffset);
	void DrawBand(CDC* pDC, RECT& rcBand);

public:
	UINT m_uLower;
	UINT m_uUpper;
	UINT m_uPosY;
	UINT m_uPreviousPosY;
	UINT m_uOffset;			
	CPen m_pen;
	CString m_strName;
	UINT m_uDotOffset;

private:	
	UINT GetAverage();

private:	
	CList<UINT, UINT&> m_List;
};

/////////////////////////////////////////////////////////////////////////////
// COscilloscopeCtrl
//////////////////////////////////////////////////////////////////////////
class COscilloscopeCtrl : public CWnd
{
	// Construction
public:
	COscilloscopeCtrl();

	// Attributes
public:

	// Operations
public:

	// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(COscilloscopeCtrl)
	//}}AFX_VIRTUAL

	// Implementation
public:
	virtual ~COscilloscopeCtrl();

	// Generated message map functions
protected:
	//{{AFX_MSG(COscilloscopeCtrl)
	afx_msg void OnPaint();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

public:
	enum Speed
	{
		spdLow = 3000,
		spdNormal = 1200,
		spdHigh = 800,
		spdIdle = 0
	};

	CArray<COscilloscopeBand*, COscilloscopeBand*> m_Bands;

public:
	BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT uID);
	int Width() { return m_rcClient.Width(); }
	int Height() { return m_rcClient.Height(); }
	void SetOffset(UINT uDot, UINT uGrid);

	BOOL SetGridColor(COLORREF crGrid);
	BOOL SetBkColor(COLORREF crBk);	

	void SetName(int nBand, LPCTSTR lpszName) { m_Bands[nBand]->SetName(lpszName); }
	CString GetName(int nBand) {return m_Bands[nBand]->m_strName; }
	void SetRange(int nBand, UINT uLower, UINT uUpper) { m_Bands[nBand]->SetRange(uLower, uUpper); }
	void SetPen(int nBand, int nWidth, COLORREF crColor) { m_Bands[nBand]->SetPen(nWidth, crColor); }
	void SetPos(int nBand, UINT uPos) { m_Bands[nBand]->SetPos(uPos); }
	void DrawBands();

private:
	BOOL InvalidateCtrl();

private:
	enum Speed m_nSpeed;

	CDC* m_pMemDC;
	CRect m_rcClient;

	COLORREF m_crBackGround;
	COLORREF m_crGrid;

	UINT m_uDotOffset;
	UINT m_uGridOffset;
	UINT m_uOffset;
	int m_nFirstLinePos;
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line
#endif // !defined(OSCILLOSCOPECTRLH)
